<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=\, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <input value="" type="text" id="num1"> + <input type="text" id="num2"> = <input type="text" id="sum">
    <p>
        <button onclick="add()">相加</button>
    </p>
    <script>
        function add() {
            // 获取元素阶段
            var $num1 = document.getElementById('num1');
            var $num2 = document.getElementById('num2');
            var $sum = document.getElementById('sum');

            // 获取input标签的值
            var num1 = $num1.value;
            var num2 = $num2.value;
            var sum = Number(num1) + Number(num2);
            $sum.value = sum;
        }
    </script>
</body>

</html>